Extending PageSentry Using AppleEvents

When a problem is detected with one of your Web pages, PageSentry can send a notification via AppleEvents to any application you like. This application will most likely be an AppleScript that will either perform some function itself or extract the event information and send another AppleEvent to another application for processing.

An example of each type of script is included in this package, and we'll look at both. But first, here are the technical details of the AppleEvent that PageSentry sends for a notification. In order to make sense of this information, it will be best if you are familair with using AppleScript to send and/or receive AppleEvents. If you aren't, you may be able to use the examples to get started, but this chapter is not intended to be a primer on either AppleScript or AppleEvents.

The notification event PageSentry sends is called "SENTfail". (The event class is "SENT" and the specific event is "fail".) The event includes several parameters which you can extract and use in your application:

In almost all cases, you can start with the following simple AppleScript shell. These few lines will put the parameters passed from PageSentry into the variables "SentryName", "FailedURL", "Extra", and "Status". You can then add whatever code you like to perform the notification you need.

    --- PageSentry Notification Receiver
    on <<event SENTfail>> sentryName given <<class
    FURL>>:failedURL, <<class XTRA>>:extra, <<class
    STAT>>:Status

    --- This is where you would do your thing...
    
    end <<event SENTfail>>
Example 1

The first example, "DisplayDialog", will display a dialog box with the error information in it. This script is very simple and does nothing except extract the paramaters out of the event and display a dialog box. The code looks like this:

    --- PageSentry Notification Applet: DisplayDialog
    on <<event SENTfail>> sentryName given <<class
    FURL>>:failedURL, <<class XTRA>>:extra, <<class
    STAT>>:Status
    
        display dialog "Received Sentry Event" & return
        & return & "SentryName: " & sentryName &        return & "failed URL: " & failedURL & return
        & "Extra: " & extra & return & "Status:
        " & Status
    
    end <<event SENTfail>>
To compile this script using the Script Editor, follow these steps:

Example 2

The second example, "SendPage_PageNow", is only slightly more complicated. In this case, we will be passing the data from the notification event off to another application, "PageNow!", for processing. PageNow! will take the AppleEvent and send an alphanumeric page to your pager.

    --- PageSentry Notification Applet
    --- SendPage Alphanumeric Pager (for use
    --- with "PageNow")

    on «event SENTfail» sentryName given «class FURL»:failedURL,
    «class XTRA»:extra, «class STAT»:Status

        set Message to sentryName & "-" & Status &        " " & failedURL

        --- To use Notify running on another machine, use:
        --- tell application "PageNOW!™ Demo" of machine
        --- "PageServer" of zone "PageServerZone"        
        tell application "PageNOW!™ Demo"        
            send page Message to extra
            
        end tell

    end «event SENTfail»
The "set Message" line builds a message that will be sent to the pager by concatenating the variables passed from PageSentry. "Tell application" is the AppleScript command to send an AppleEvent to another application, in this case, the "PageNOW!™ Demo" application (which may be running on another Macintosh).

This example uses AppleScript as "glue" to tie PageSentry to another application. By understanding both the notification event coming from PageSentry and the paging event supported by Notify!, the applet can tie the two applications together with very little code.

This example also makes use of the "extra" parameter to specify the name of the person (as defined in PageNow!) to be paged. This is just one example of how the "extra"parameter can be used to allow multiple sentries to use the same AppleScript applet to do slightly different things. If all of the pages were to be sent to a single recipient, we could simplify this example even more by "hard coding" the recipient's name in place of using the "extra" parameter to insert it.


[ Previous | Table Of Contents | Next ]

Copyright © 1996 Maxum Development Corporation
820 South Bartlett Road - Suite 104
Streamwood, IL 60107
http://www.maxum.com/